﻿CREATE PROCEDURE [dbo].[SaveWorkflowDesign]
(
	@WorkflowGuid varchar(50),
	@WorkflowName varchar(255),
    @Version varchar(25),
    @CreationTime datetime,
    @ModificationTime datetime,
    @Author varchar(255),
    @Description varchar(1000),
    @FailureNotifyEmailAddress varchar(255),
	@XDoc text,
    @DesignDocumentFilePath varchar(1000),
    @CheckOutTime datetime,
    @CheckOutBy varchar(255),
    @IsLocked bit
) as 
begin
	declare @exist int
	set @exist=(select count(*) from WorkflowDesign where WorkflowGuid=@WorkflowGuid)
	
	if(@exist>0) begin
		update WorkflowDesign 
		set
			WorkflowName=@WorkflowName,
			Version=@Version,
			CreationTime=@CreationTime,
			ModificationTime=@ModificationTime,
			Author=@Author,
			Description=@Description,
			FailureNotifyEmailAddress=@FailureNotifyEmailAddress,
			XDoc=@XDoc,
			DesignDocumentFilePath=@DesignDocumentFilePath,
			CheckOutTime=@CheckOutTime,
			CheckOutBy=@CheckOutBy,
			IsLocked=@IsLocked 
		where 
			WorkflowGuid=@WorkflowGuid
	end
	else begin
		insert into WorkflowDesign 
			(WorkflowGuid, 
			WorkflowName,
			Version,
			CreationTime,
			ModificationTime,
			Author,
			Description,
			FailureNotifyEmailAddress,
			XDoc,
			DesignDocumentFilePath,
			CheckOutTime,
			CheckOutBy,
			IsLocked) 
		values 
			(@WorkflowGuid, 
			@WorkflowName,
			@Version,
			@CreationTime,
			@ModificationTime,
			@Author,
			@Description,
			@FailureNotifyEmailAddress,
			@XDoc,
			@DesignDocumentFilePath,
			@CheckOutTime,
			@CheckOutBy,
			@IsLocked)
	end 
END


